package com.bjc.nio;

import java.nio.ByteBuffer;

/**
 * @program: nettypro
 * @description: buffer  put 和get 类型要一致
 * @author: bjc
 * @create: 2021-09-03 21:42
 */
public class NIOBufferPutGet {

    public static void main(String[] args) {
        //创建一个buffer
        ByteBuffer buffer = ByteBuffer.allocate(64);

        //类型化方式放入数据
        buffer.putInt(100);
        buffer.putLong(9L);
        buffer.putChar('A');
        buffer.putShort((short) 4);

        //取出
        buffer.flip();
        System.out.println();

        System.out.println(buffer.getInt());
        System.out.println(buffer.getLong());
        System.out.println(buffer.getChar());
        System.out.println(buffer.getShort());
    }
}
